package com.project.fiveCerealsSavoury.service.impl;

import java.util.Date;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.project.fiveCerealsSavoury.dao.LogisticsDao;
import com.project.fiveCerealsSavoury.domain.LogisticsDomain;
import com.project.fiveCerealsSavoury.domain.LogitsticsState;
import com.project.fiveCerealsSavoury.exception.BizException;
import com.project.fiveCerealsSavoury.service.LogisticsService;
import com.project.fiveCerealsSavoury.transfer.LogAdd;

@Service
public class LogisticsServcieImpl implements LogisticsService {

	@Autowired
	LogisticsDao logisticsDao;

	@Override
	public boolean add(@Valid LogisticsDomain logisticsDomain ) throws BizException{
		if (logisticsDomain.getName() == null)
			throw new BizException("公司不为null");
		if (logisticsDomain.getStartAddress() == null)
			throw new BizException("发送不为null");
		if (logisticsDomain.getDeliverGoods() == null)
			throw new BizException("物流状态不为null");
		if (logisticsDomain.getDeliveryTime() == null)
			throw new BizException("时间不为null");
		if (logisticsDomain.getDeliveryId() == null)
			throw new BizException("送货人ID不为null");
		if (logisticsDomain.getWaybillId()==null)
			throw new BizException("运单号ID不为null");
		if (logisticsDomain.getIndentId()==null)
			throw new BizException("订单ID不为null");
	
		logisticsDao.add(logisticsDomain);
		
		return true;
		
	}
	@Override
	public boolean addLog(LogAdd logAdd) throws BizException {
		if (logAdd.getDeliveryId() == null)
			throw new BizException("送货人ID不为null");
		if (logAdd.getWaybillId()==null)
			throw new BizException("运单号ID不为null");
		if (logAdd.getOrderId()==null)
			throw new BizException("订单ID不为null");
		if (logAdd.getDeliverGoods() == null)
			throw new BizException("物流状态不为null");
		
		logisticsDao.addLog(logAdd);
		return true;
	}

	@Override
	public List<LogisticsDomain> queryNottosend(Integer waybillId, LogitsticsState logitsticsState) throws BizException {
		if (logitsticsState == null)
			throw new BizException("物流信息不为null");
		return logisticsDao.queryNottosend(waybillId,logitsticsState);
	
	}
	@Override
	public List<LogisticsDomain> queryTime(Date deliveryTime) throws BizException {
		if (deliveryTime == null)
			throw new BizException("时间不为null");
		return logisticsDao.queryTime(deliveryTime);
	
	}

	@Override
	public void amend(LogitsticsState logitsticsState) throws BizException {
		if (logitsticsState == null)
			throw new BizException("送货人状态不为null");
		
	}
	@Override
	public List<LogisticsDomain> queryIndent(Integer id) throws BizException{
		if (id == null)
			throw new BizException("订单不为null");
		return logisticsDao.queryIndent(id);
	}

}
